package com.hn.zhijian.system.config;

import com.hn.zhijian.base.common.ConfigurationYmlProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;
import javax.servlet.MultipartConfigElement;

/**
 * @author carl chen
 * @Classname 设置文件上传大小
 * @Description TODO
 * @Date 2019/11/8 15:19
 */
@Configuration
public class MultipartConfig {

    @Autowired
    private ConfigurationYmlProperty config;

    @Bean
    public MultipartConfigElement multipartConfigElement(){

        MultipartConfigFactory factory = new MultipartConfigFactory();

        //  单个数据大小
        factory.setMaxFileSize(DataSize.ofMegabytes(config.getSoleFileMaxSize()));
        /// 总上传数据大小
        factory.setMaxRequestSize(DataSize.ofGigabytes(config.getMultipleFileMinSize()));

        return factory.createMultipartConfig();
    }
}
